package com.ce.utils;

import java.text.DecimalFormat;

public class MathUtils {

	
	public static float getFloatFromStr(String str) {
		float f = 0.0f;
		try{
			f = Float.parseFloat(str);
		}catch(Exception exception) {
			f = 0.0f;
		}
		return f;
	}
	
	public static String formatDecimal(double value) {
		return formatDecimal(value, "#.00");
	}
	
	public static String formatDecimal(double value, String pattern) {
		DecimalFormat fmt = null;
		String numStr = "";
		try{
			fmt = new DecimalFormat(pattern);
			numStr = fmt.format(value);
		}catch(Exception e) {
			e.printStackTrace();
		}
		if(Math.abs(value) < 1)
			return "0" + numStr;
		return numStr;
	}
}
